#!/usr/bin/python
# coding=utf-8

import codecs
import re

def sanitize(adjective):
  bad_chars_replacement = {'á':'a', 'é':'e', 'í':'i', 'ó':'o', 'ú':'u', 'ñ':'n'}
  for c in bad_chars_replacement.keys():
    adjective.replace(c,bad_chars_replacement[c])

generic = re.compile(u"^.*(ch.|ista|ense|ar|[elz]|rc.|[^úó][n])$")
def is_generic(adjective):
  return not (generic.match(adjective) is None)

def singular_form(adjective):
  if adjective[-1] == 's':
    if adjective[-3:] == 'ces':
      adjective = adjective[:-3] + 'z'
    else:
      adjective = adjective[:-1]
  return adjective

def male_form(adjective):
  if not is_generic(adjective):
    if adjective[-1] == 'a':
      adjective = adjective[:-1]
      if adjective[-1] != 'r':
          adjective += 'o'
  return adjective
